﻿using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using élénkPróbája.helpers;
using élénkPróbája.Test.extention;
using élénkPróbája.validators;

namespace élénkPróbája.Test
{
    [TestClass]
    public class AssemblyScannerTester
    {

        [TestMethod]
        public void Finds_validators_for_types()
        {
            var scanner = new AssemblyScanner(new[] {typeof (Model1Validator), typeof (Model2Validator)});
            var results = scanner.ToList();

            results[0].ValidatorType.ShouldEqual(typeof (Model1Validator));
            results[0].InterfaceType.ShouldEqual(typeof (IValidator<Model1>));

            results[1].ValidatorType.ShouldEqual(typeof (Model2Validator));
            results[1].InterfaceType.ShouldEqual(typeof (IValidator<Model2>));

        }

        [TestMethod]
        public void ForEach_iterates_over_types()
        {
            var scanner = new AssemblyScanner(new[] { typeof(Model1Validator), typeof(Model2Validator) });
            var results = new List<AssemblyScanner.AssemblyScanResult>();

            scanner.ForEach(x => results.Add(x));
            results.Count.ShouldEqual(2);
        }
        public class Model1
        {

        }

        public class Model2
        {

        }

        public class Model1Validator : AbstractValidator<Model1>
        {
        }

        public class Model2Validator : AbstractValidator<Model2>
        {

        }

    }
}
